//
//  KABMineMsgTCell.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/12.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABMineMsgTCell.h"
#import "GlobalHeader.h"
#import "UIColor+XDHex.h"
#import "KABModel.h"
#import <YYWebImage.h>

@implementation KABMineMsgTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.portraintImgView.layer.masksToBounds = YES;
    self.portraintImgView.layer.cornerRadius = CGRectGetWidth(self.portraintImgView.bounds) / 2.0;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(portraitImgViewTapped:)];
    [self.portraintImgView addGestureRecognizer:tapGesture];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)portraitImgViewTapped:(UIGestureRecognizer *)gesture {
    if ([self.delegate respondsToSelector:@selector(kABMineMsgTCell:portraitTapped:)]) {
        [self.delegate kABMineMsgTCell:self portraitTapped:(UIImageView *)gesture.view];
    }
}

- (void)configViewWithMsgItem:(KABMineMsgItem *)item {
    [self.portraintImgView yy_setImageWithURL:[NSURL URLWithString:item.a_headimg_url]
                                 placeholder:[KABDefaultVarModel sharedInstance].smallDefaultImg];
    
    NSDictionary *dic = @{NSForegroundColorAttributeName : [UIColor xd_colorWithHex:KABGlobalColorTabBarItemColor],
                          NSFontAttributeName : [UIFont systemFontOfSize:16.0]};
    NSString *str = [NSString stringWithFormat:@"%@ %@你的%@", item.a_nick_name, item.action, item.what];
    NSMutableAttributedString *mCosAStr = [[NSMutableAttributedString alloc] initWithString:str];
    [mCosAStr addAttributes:dic range:NSMakeRange(0, item.a_nick_name.length)];
    self.nameLabel.attributedText = mCosAStr;
    
    self.timeLabel.text = item.time;
}

@end
